package com.example.androidlearning2200;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.androidlearning2200.adapter.PagerAdapter;
import com.example.androidlearning2200.frg.TouTiaoFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class TabLayoutActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_layout);
        tabLayout = findViewById(R.id.tabLayout);
        viewPager = findViewById(R.id.viewPager);
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(TouTiaoFragment.newInstance(1));
        fragments.add(TouTiaoFragment.newInstance(2));
        fragments.add(TouTiaoFragment.newInstance(3));
        fragments.add(TouTiaoFragment.newInstance(4));
        fragments.add(TouTiaoFragment.newInstance(5));
        fragments.add(TouTiaoFragment.newInstance(6));
        // 添加更多的 Fragment
        List<String> titles = new ArrayList<>();
        titles.add("关注");
        titles.add("推荐");
        titles.add("热门");
        titles.add("国际");
        titles.add("体育");
        titles.add("军事");
        PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(), fragments, titles);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }
}

